<?php $this->fetch('public/head') ?>
<style>
/* 下拉框样式调整 */
    .layui-tab{overflow: visible}
</style>
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">导航管理</li>
        <li class=""><a href="<?php echo url('hsnav/add') ?>">添加导航</a></li>
    </ul>
    <div class="layui-tab-content">
        <form class="layui-form layui-form-pane" action="<?php echo url('hsnav/index') ?>" method="get">
            <div class="layui-inline">
                <label class="layui-form-label">所属分类</label>
                <div class="layui-input-inline">
                    <select name="nav_cid">
                        <?php foreach($navcat_list as $k=>$v): ?>
                        <option value="<?php echo $k ?>" <?php echo $k==$nav_cid?'selected="selected"':''; ?>><?php echo $v ?></option>
                    	<?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn">搜索</button>
            </div>
        </form>
        <hr>
        <div class="layui-tab-item layui-show">
            <table class="layui-table">
                <thead>
                <tr>
                    <th style="width: 60px;">展开</th>
                    <th style="width: 50px;">排序</th>
                    <th style="width: 30px;">ID</th>
                    <th>导航名称</th>
                    <th>导航分类名称</th>
                    <th>链接</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach($nav_level_list as $v){?>
                <?php $url = url('hsnav/setStatus?id='.$v['id']) ?>
                <tr class="level_<?php echo $v['level']==1?'one':($v['level']==2?'two':'three') ?> level_<?php echo $v['pid'] ?>"  data-id="<?php echo $v['id'] ?>" data-pid="<?php echo $v['pid'] ?>">
                    <td <?php if($v['son']){echo 'class="open_level"';} ?>>
                        <?php echo str_repeat('&nbsp;',($v['level']-1)*2) ?><i class="layui-icon" data-id="<?php echo $v['id'] ?>" style="font-size: 25px;<?php if(!$v['son']){echo 'color: #ccc;';} ?>">&#xe623;</i>
                    </td>
                    <td>
                        <input class="layui-input" name="sort" required="" lay-verify="required" placeholder="" autocomplete="off" type="text" id="change_sort_<?php echo $v['id'] ?>" value="<?php echo $v['sort'] ?>" data-url="<?php echo $url ?>" onchange="change_sort(<?php echo $v['id'] ?>)">
                    </td>
                    <td><?php echo $v['id'] ?></td>
                    <td><?php echo $v['level']>1?str_repeat('&nbsp;&nbsp;&nbsp;└─',$v['level']-1):'',$v['name'],$v['alias']?' - '.$v['alias']:'' ?></td>
                    <td><?php echo $navcat_list[$v['nav_cid']] ?></td>
                    <td><?php echo $v['link'] ?></td>
                    <td>
                        <?php if($v['status']==1): ?>
                        <a href="<?php echo $url ?>" data-param="status=0" class="layui-btn layui-btn-xs ajax-post">显示</a>
                        <?php else: ?>
                        <a href="<?php echo $url ?>" data-param="status=1" class="layui-btn layui-btn-danger layui-btn-xs ajax-post">隐藏</a>
                        <?php endif; ?>
                    </td>
                    <td>
                        <a href="<?php echo url('hsnav/add',['pid'=>$v['id'],'nav_cid'=>$v['nav_cid']]) ?>" class="layui-btn layui-btn-xs">添加子导航</a>
                        <a href="<?php echo url('hsnav/edit',['id'=>$v['id'],'nav_cid'=>$v['nav_cid']]) ?>" class="layui-btn layui-btn-normal layui-btn-xs">编辑</a>
                        <a href="<?php echo url('hsnav/delete?id='.$v['id']) ?>" class="layui-btn layui-btn-danger layui-btn-xs ajax-delete">删除</a>
                    </td>
                </tr>
                <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php $this->fetch('public/script') ?>
<script src="_js/menu.js"></script>
<script>
//修改排序值
function change_sort(id){
    var sort = $("#change_sort_"+id).val();
    var _url = $("#change_sort_"+id).attr("data-url");
    $.ajax({
        type:'POST',
        url:_url,
        dataType: "json",
        data:{"sort":sort},
        success:function(info){
            if (info.code === 1) {
                setTimeout(function () {
                    location.href = info.url;
                }, 1000);
            }
            layer.msg(info.msg);
        }
    })
}
</script>